<div class="form-group">
    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
    <div class="col-sm-9 col-xs-12">
        <div id="modal-module-menus"  class="modal fade" tabindex="-1">
            <div class="modal-dialog" style='width: 920px;'>
                <div class="modal-content">
                    <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择新的上级 <small>注意：变更上级功能，无法改变用户之前的订单及佣金。</small></h3></div>
                    <div class="modal-body" >
                        <div class="row" style="padding: 0 20px;">
                            <div class="input-group">
                            	<input type="hidden" name="original" />
                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd" placeholder="请输入粉丝昵称/姓名/手机号" />
                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_members();">搜索</button></span>
                            </div>
                        </div>
                        <div id="module-menus" style="padding-top:5px;"></div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-info" onclick="change_empty();">变更上级为总店</button>
                        <a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script language='javascript'>

function popwin(uid){
    $('#modal-module-menus input[name="original"]').val(uid);
    $('#modal-module-menus').modal();
    
    console.log(uid);
}

function search_members() {
    var keyword = $.trim($('#search-kwd').val());
    if (keyword == '') {
        Tip.focus('#search-kwd', '请输入关键词');
        return;
    }
    $("#module-menus").html("正在搜索....");
    $.get("{php echo $this->createWebUrl('member/query')}", { keyword: keyword }, function (dat) {
        console.log(dat);
        $('#module-menus').html(dat);
    });
}

function select_member(o) {
	
    if ($('.multi-item[openid="' + o.openid + '"]').length > 0) {
        return;
    }
    
    $("#module-menus").html("已确认，正在修改上级为："+o.nickname+'<br />'+'修改完成后，页面将自动刷新。');
    
    data = {
	    'ouid' : $('#modal-module-menus input[name="original"]').val(),
	    'auid'  : o.id,
	    'token' : "{$_W['token']}",
    };
    
    $.ajax({
		url:"{php echo $this->createPluginWebUrl('commission/agent/change');}",// 跳转到 action
		data:data,
		type:'post',
		dataType:'json',
		success:function(data){
		    if(data.type == 'success'){
				$("#module-menus").html(data.message);
				//$('#modal-module-menus').modal('hide');
				location.reload();
		    }else{
				$("#module-menus").html(data.message);
		    }
		    
			return true;
		},
		error : function(){
			alert("异常！");
		}
	});
    
}

function change_empty() {

    $("#module-menus").html("已确认，正在修改上级为：总店，修改完成后，页面将自动刷新。");

    data = {
        'ouid' : $('#modal-module-menus input[name="original"]').val(),
        'auid'  : 0,
        'token' : "{$_W['token']}",
        'empty' : 1
    };

    $.ajax({
        url:"{php echo $this->createPluginWebUrl('commission/agent/change');}",// 跳转到 action
        data:data,
        type:'post',
        dataType:'json',
        success:function(data){
            if(data.type == 'success'){
                $("#module-menus").html(data.message);
                //$('#modal-module-menus').modal('hide');
                location.reload();
            }else{
                $("#module-menus").html(data.message);
            }

            return true;
        },
        error : function(){
            alert("异常！");
        }
    });

}




function remove_member(obj) {
    $(obj).parent().remove();
    refresh_members();
}

function refresh_members() {
    var nickname = "";
    $('.multi-item').each(function () {
        nickname += " " + $(this).find('.img-nickname').html() + "; ";
    });
    $('#salers').val(nickname);
}

</script>
